$(function () {
    $("#jqGrid").jqGrid({
        url: baseURL + 'sys/sysAgent/forbidTakeList',
        datatype: "json",
        data:{'state':3},
        colModel: [			
			{ label: '推荐码', name: 'agentId', index: "agent_id", width: 45, key: true,align:"center" },
			{ label: '渠道名称', name: 'deptName', index: "deptName", width: 75,align:"center" },
			{ label: '合伙人姓名', name: 'name', width: 60,align:"center" },
			{ label: '手机号码', name: 'phone', width: 75,align:"center"},
            { label: '角色', name: 'type', width: 45,align:"center",formatter:function(value,options,row){
                    return value == 3 ? '盟主':'普通'
                } },
            { label: '推荐人', name: 'parentName', width: 60,align:"center"},
			{ label: '账户总分润', name: 'totalAmount', index: "totalAmount", width: 75,align:"center",formatter:function(value, options, row){
                    if(value==0 ||value==null){
                        return '0.00';
                    }
                    return value;
			}},
            { label: '账户余额', name: 'availableAmount', index: "availableAmount",align:"center", width: 75,formatter:function(value, options, row){
                    if(value==0 ||value==null){
                        return '0.00';
                    }
                    return value;
                }},
            { label: '冻结资金', name: 'freeznAmount', index: "freeznAmount", width: 75,align:"center",formatter:function(value, options, row){
                    if(value==0 ||value==null){
                        return '0.00';
                    }
                    return value;
                }},
            { label: '登录状态', name: 'state', width: 60,align:"center", formatter: function(value, options, row){
                    return value === 3 ?
                        '<span class="label label-danger">禁止提现</span>' :
                        '<span class="label label-success">正常</span>';
                }},
            { label: '验证状态', name: 'realName', width: 60,align:"center"},
			{ label: '账号创建时间', name: 'createTime', index: "create_time", width: 85,align:"center"},
            { label: '操作',name:'agentId',align:"center",formatter:function(value, options, row){
                      return  '<span class = "btn btn-success" onclick = "unforbidAgent('+value+')"> 解禁 </span>&nbsp;&nbsp;';
                }}

        ],
		viewrecords: true,
        height: 385,
        rowNum: 10,
		rowList : [10,30,50],
        rownumbers: true, 
        rownumWidth: 25, 
        autowidth:true,
        pager: "#jqGridPager",
        jsonReader : {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        prmNames : {
            page:"page",
            rows:"limit",
            order: "order",
            state:3
        },
        gridComplete:function(){
        	//隐藏grid底部滚动条
        	$("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" }); 
        }
    });

});

function unforbidAgent(aId){
    vm.agent.agentId=aId;
    confirm("确认要解禁该合伙人？",function () {
        vm.agent.state=1;
        $.ajax({
            type: "POST",
            url: baseURL + "sys/sysAgent/freezAgent",
            contentType: "application/json",
            data: JSON.stringify(vm.agent),
            success: function(r){
                if(r.code == 0){
                    alert('操作成功',function(){
                        vm.reload();

                    });

                }else{
                    alert(r.msg);
                }
            }
        });
    })

}
var vm = new Vue({
    el:'#rrapp',
    data:{
        q:{
            phone: null,
            name:null,
        },
        showList: true,
        agent:{
            agentId:null,
            state:null
        }
    },
    methods: {
        query: function () {
            vm.reload();
        },
        clean:function(){
            vm.q={
                phone: null,
                name:null,
            };
            vm.reload();
        },
        reload: function () {
            $("#jqGrid").jqGrid('setGridParam',{
                postData:{'phone': vm.q.phone,'name':vm.q.name},
                page:1
            }).trigger("reloadGrid");
        }

    }
});

